package com.atguigu.cloud.controller.feign;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.atguigu.cloud.domain.Document;
import com.atguigu.cloud.dto.DocumentDto;
import com.atguigu.cloud.feign.DocumentFeign;
import com.atguigu.cloud.service.DocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/feign/document")
@RestController
public class DocumentFeignController implements DocumentFeign {

    @Autowired
    private DocumentService documentService;

    @RequestMapping("/getDocumentList")
    public List<DocumentDto> getDocumentList() {
        List<Document> list = documentService.list();
        return CollUtil.isEmpty(list) ? new ArrayList<>() : BeanUtil.copyToList(list, DocumentDto.class);

    }
}
